#include <iostream>
#include <vector>
using namespace std;
 
int main(){
	freopen("in.txt","r",stdin);
    int n,X;
	cin>>X;
    cin>>n;
	vector<int> price;
	int total=0;
	int p;
	while(cin >> p){
		price.push_back(p);
		total+=p;
	}
	int V=total-X;
	vector<int> dp(V+1,0);
	for(int i=1;i<=n;i++)
		for(int j=V;j>=price[i-1];j--){
				dp[j]=max(dp[j-price[i-1]]+price[i-1],dp[j]);
		}
	cout<<total-dp[V]-n<<endl;
    
    return 0;
}